package calendar.messages;

import calendar.User;
import edu.gmu.middleware.Message;
import edu.gmu.streams.BlockInputStream;
import edu.gmu.streams.BlockOutputStream;
import java.io.IOException;

/* this class represents a single user */
import java.util.Date;
public class RetrieveRequest implements Message
{
  public User user;
  public Date start;
  public Date end;
  
  public RetrieveRequest()
  {
    
  }

  public void marshal(BlockOutputStream stream) throws IOException
  {
    this.user.marshal( stream );
    
    stream.writeBoolean( this.start != null );
    if( this.start != null )
    {
        stream.writeLong( start.getTime() );
    }
    
    stream.writeBoolean( this.end != null );
    if( this.end != null )
    {
        stream.writeLong( end.getTime() );
    }
  }

  public void unmarshal(BlockInputStream stream) throws IOException
  {
    this.user = new User();
    this.user.unmarshal( stream );
    
    boolean isStart = stream.readBoolean();
    if( isStart )
    {
        this.start = new Date( stream.readLong() );
    }
    
    boolean isEnd = stream.readBoolean();
    if( isEnd )
    {
        this.end = new Date( stream.readLong() );
    }
  }
}
